package actor.persistence

import akka.actor.{Actor, ActorLogging, Props}

/**
 * @Description: TODO
 * @Author: DJJ
 * @Date: 2019/12/28 14:05
 */
object EventTracker  {
  def props = Props(new EventTracker)
}

class EventTracker  extends Actor with ActorLogging {

  override def preStart(): Unit = {
    //订阅
    context.system.eventStream.subscribe(self, classOf[Calculator.LogMessage])
    super.preStart()
  }

  override def receive: Receive = {
    case Calculator.LogMessage(msg) => println(msg)
  }

  override def postStop(): Unit = {
    context.system.eventStream.unsubscribe(self)
    super.postStop()
  }
}